<template>
	<view class="wrap p-2">
		<div v-if="hasLogin">
			<u-button  type="primary" @click="toAdd">添加活动</u-button>
		</div>
		<div class="events-list flex-auto overflow-auto h-10">
      <div v-for="(item,index) in event_list" :key="index" @click="view(item._id)">
        <m-card customClass="my-2 p-2" bodyAuto>

          <div class="w-full h-full">
          	<u-image width="100%" height="300rpx" :src="item.fileList.length>0?item.fileList[0].url:''"></u-image>
          </div>
          <div class="">
          	<p class="py-1 text-base font-bold">{{item.name}}</p>
          	<p class="text-gray-400">{{item.info}}</p>
          	<div class="flex">
          		<p class="mr-2"><span class="text-gray-600">会议室:</span>{{item.address}}</p>
          		<p class=""><span class="text-gray-600">时间:</span>{{$utils.timestampToTime(item.create_date)}}</p>
          	</div>
          	<!-- <p>
          		<u-button @click="edit(item._id)">修改</u-button>
          	</p> -->
          </div>
        </m-card>
      </div>
			<div class="event-list-item" v-for="(item,index) in event_list" :key="index" @click="view(item._id)" v-if="false">
				<div v-for="(sitem,i) in item.fileList" :key="i" class="img-box">
					<u-image width="100%" height="100%" :src="sitem.url"></u-image>
				</div>
				<div class="main-box">
					<p class="title">{{item.name}}</p>
					<p class="info">{{item.info}}</p>
					<div class="item-other">
						<p class="addr">会议室:{{item.address}}</p>
						<p class="date">时间:{{$utils.timestampToTime(item.create_date)}}</p>
					</div>
					<!-- <p>
						<u-button @click="edit(item._id)">修改</u-button>
					</p> -->
				</div>
			</div>
		</div>
		<m-tab-bar></m-tab-bar>
	</view>
</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	export default {
		data() {
			return {
				event_list: []
			}
		},
		computed: mapState(['hasLogin']),
		onLoad() {
			// location.reload()
		},
		onShow() {
			this.getList()
		},
		methods: {
			view(id) {
				uni.navigateTo({
					url: './operation?id=' + id,
				});
			},
			toAdd() {
				uni.navigateTo({
					url: './operation',
				});
			},
			getList() {
				uni.showLoading({
					title: '加载中...'
				})
				this.$reqFun.req("events", {
					action: 'list'
				}).then(res => {
					uni.hideLoading()
					this.event_list = res.result.data
				})
				// uniCloud.callFunction({
				// 	name: "events",
				// 	data: {
				// 		action: 'list'
				// 	},
				// 	success: (res) => {
				// 		uni.hideLoading()
				// 		console.log(res)
				// 		this.event_list = res.result.data
				// 	},
				// 	fail: (err) => {
				// 		uni.hideLoading()
				// 		console.log(err)
				// 	}
				// })
			}
		}
	}
</script>

<style lang="scss" scoped>
	@import "./events.scss";
</style>
